home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / askrunlevel / modules.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  2.0 KB  |  104 lines

  1. #include <unistd.h>
  2. #include <limits.h>
  3. #include "askrunlevel.h"
  4. #include "../misc/misc.h"
  5. #include "../netconf/netconf.h"
  6. #include "../paths.h"
  7.  
  8. #if 0
  9.  
  10. struct PARMDESC{
  11.     const char *parm;
  12.     const char *desc;
  13. };
  14.  
  15. enum USAGE_MODE {
  16.     USAGE_KERNELD,        // On demand loading
  17.     USAGE_BOOT,        // Load at boot time
  18.     USAGE_MANUAL.        // Don't load automaticly
  19.     USAGE_KERNELD_STICK,    // Load once with kerneld
  20. };
  21.  
  22. class MODULE: public ARRAY_OBJ{
  23.     SSTRING name;
  24.     const PARMDESC *opts;    // Array of configurable parameter
  25.     SSTRINGS values;    // With values
  26.     USAGE_MODE umode;
  27.     /*~PROTOBEG~ MODULE */
  28.     /*~PROTOEND~ MODULE */
  29. };
  30.  
  31. #endif
  32.  
  33. /*
  34.     Make sure the modules are properly installed
  35.     Return 0 if nothing at all, 1 if the directory exist, 2 if modules.dep
  36.     exist.
  37. */
  38. static int modules_installed()
  39. {
  40.     int ret = 0;
  41.     int v[3];
  42.     /* #Specification: modules / depmod
  43.         linuxconf will call "depmod -a" if /lib/modules/kernel_version
  44.         exist and /lib/modules/kernel_version/modules.dep do not exist
  45.     */
  46.     if (kernel_version(v)!=-1){
  47.         char path[PATH_MAX];
  48.         sprintf (path,"%s/%d.%d.%d",LIB_MODULES,v[0],v[1],v[2]);
  49.         if (file_exist(path)){
  50.             ret = 1;
  51.             sprintf (path,"%s/%d.%d.%d/modules.dep",LIB_MODULES,v[0],v[1],v[2]);
  52.             if (file_exist(path)){
  53.                 ret = 2;
  54.             }
  55.         }
  56.     }
  57.     return ret;
  58. }
  59. /*
  60.     Make sure the modules are properly installed
  61. */
  62. void modules_check()
  63. {
  64.     if (modules_installed()==1){
  65.         netconf_system_if ("depmod","-a");
  66.     }
  67.     {
  68.         int avail = modules_avail();
  69.         if (avail != -1) netconf_startstop ("kerneld",avail);
  70.     }
  71. }
  72.  
  73. /*
  74.     Return 1 if there are some kernel modules available on this system,
  75.         0 if there are none or -1 if it can't be sure.
  76. */
  77. int modules_avail ()
  78. {
  79.     int ret = -1;
  80.     if (modules_installed()==2){
  81.         DAEMON *dae = daemon_find ("modprobe");
  82.         if (dae != NULL && dae->is_managed()){
  83.             char cmd[200];
  84.             sprintf (cmd,"%s -l",dae->getpath());
  85.             FILE *fin = popen (cmd,"r");
  86.             ret = 0;
  87.             if (fin != NULL){
  88.                 char buf[300];
  89.                 if (fgets(buf,sizeof(buf)-1,fin)!=NULL) ret = 1;
  90.                 fclose (fin);
  91.             }
  92.         }
  93.     }
  94.     return ret;
  95. }
  96.  
  97. /*
  98.     Just to ease linking
  99. */
  100. void modules_dummy()
  101. {
  102. }
  103.  
  104.